//
//  AYMSettingController.m
//  QuickCure
//
//  Created by 徐绩 on 16/5/6.
//  Copyright © 2016年 ayumi. All rights reserved.
//

#import "AYMSettingController.h"
#import "AYMSuggestionController.h"
#import "AYMModifyPSWController.h"
#import "AYMPlusServiceController.h"
#import "AYMForceTouchClik.h"

@interface AYMSettingController ()

@property (nonatomic,strong) NSArray *titleLabel;

@end

static NSString *ID = @"settingCell";
@implementation AYMSettingController

- (void)viewDidLoad {
    [super viewDidLoad];
    
     self.title = @"设置与帮助";
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:ID];
    
    self.titleLabel = @[@"意见反馈",@"加号符号说明",@"修改密码",@"注销用户"];
    UIView *footerView = [[UIView alloc]init];
    self.tableView.tableFooterView = footerView;
}


#pragma mark - Table view data source

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 4;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    cell.textLabel.text = self.titleLabel[indexPath.row];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row == 0) {
        
        //意见与反馈
        AYMSuggestionController *suggestionVC = [[AYMSuggestionController alloc]init];
        [self jumpToTargetVC:suggestionVC];
    }else if (indexPath.row == 1){
        
        //加号符号说明
        AYMPlusServiceController *plusServiceVC = [[AYMPlusServiceController alloc]init];
        [self jumpToTargetVC:plusServiceVC];
    
    }else if (indexPath.row == 2){
    
        //修改密码
        AYMModifyPSWController *modifyVC = [[AYMModifyPSWController alloc]init];
        [self jumpToTargetVC:modifyVC];
    }else{
    
        //注销用户
        [self logoutCellClick];
    }
}



#pragma mark - 注销用户登录
-(void)logoutCellClick{

    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"您确定要退出吗?" preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *logout = [UIAlertAction actionWithTitle:@"注销" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
    NSArray *fileArr=[[NSFileManager  defaultManager] subpathsOfDirectoryAtPath:NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] error:nil];
        
     for (NSString *fileName in fileArr) {
            
            NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:fileName];
             [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
            
        }
        
        
        
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isUserLogiKey"];
        [AYMForceTouchClik loginForceTouch];
        [[UserData sharedInstance]cleanUserInfo];
        self.logoutBlock();
        [self.navigationController popToRootViewControllerAnimated:YES];
        
    }];
    [alertVC addAction:cancel];
    [alertVC addAction:logout];
    [self presentViewController:alertVC animated:YES completion:nil];

}


@end
